import React, { Component } from 'react'
import { Router, Route, Redirect, Switch } from 'react-router-dom'
// import Login from './pages/Login'
// import Layout from './pages/Layout'
import AuthRoute from 'components/AuthRoute'
import Is404 from 'pages/Is404'
import { history } from 'utils/history'
// 路由懒加载
// 当匹配到路由时，才会加载响应的路由页面
const Login = React.lazy(() => import('./pages/Login'))
const Layout = React.lazy(() => import('./pages/Layout'))

export default class App extends Component {
  render() {
    return (
      <Router history={history}>
        <React.Suspense fallback={<div>...loading</div>}>
          <Switch>
            <Route exact path="/" render={() => <Redirect to="/home" />} />
            <Route path="/login" component={Login} />
            {/* <Route path="/home" component={Layout} /> */}
            <AuthRoute path="/home" component={Layout} />
            <Route component={Is404} />
          </Switch>
        </React.Suspense>
      </Router>
    )
  }
}
